package com.smh.controller;

import com.smh.common.CommonResult;
import com.smh.entity.Device;
import com.smh.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@CrossOrigin
@RestController
@RequestMapping("device")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;
    //查询所有数据
    @RequestMapping(value = "queryAll",method = RequestMethod.GET)
    public CommonResult<ArrayList<Device>> query(){
        return deviceService.queryAll();
    }

    //添加设备
    @RequestMapping(value = "add",method = RequestMethod.POST)
    public CommonResult<Device> add(@RequestBody Device device) {
        return deviceService.add(device);
    }

    //修改设备数据
    @RequestMapping(value = "update",method = RequestMethod.POST)
    public CommonResult<Device> update(@RequestBody Device device) {
        return deviceService.update(device);
    }

    //删除数据
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    public CommonResult<Device> delete(Integer id){
       return deviceService.delete(id);
    }

    //根据id查询
    @RequestMapping(value = "queryById",method = RequestMethod.POST)
    public CommonResult<Device> queryById(Integer id){
        return deviceService.queryById(id);
    }

    @RequestMapping(value = "search",method = RequestMethod.GET)
    public CommonResult<ArrayList<Device>> search(Integer page,Integer size){
        return deviceService.listByPage(page,size);
    }

}
